Yacon.component.TMultiGrid = function(conText){
	
	Yacon.apply(this,conText);
	
	if(this.view){
		this.element = this.view;
		this.elementID = this.view.id;
		this.elementType = this.view.type;
	}
	
	this.spinner = new Yacon.widget.TSpin({page:this.page});
	
	this.dataSet = new Yacon.data.DataSet(this.page);
	this.dataSet.elementID = this.elementID;
	this.dataSet.component = this;
	
	this.isFirst = true;
	
};

Yacon.component.TMultiGrid.prototype = {
	
	/* 获取HTML */
	getHtml: function(){
		
		var html = "";
		
		html += "<div class='panel row-ht-auto col' role='multigrid' ";		
		html += " lily-id='"+this.elementID+"' lily-type='"+this.elementType+"' ";
		
		html += ">";
		
		/* 标题 */
		this.title = new  Yacon.component.TMultiGridNav({view:this.view.title,parent:this});
		html += this.title.getHtml();
		
		/* 体信息 */
		this.body = new Yacon.component.TMultiGridBody({view:this.view,parent:this});
		html += this.body.getHtml();
		
		/* 菜单部分 */
		if(this.view.title.menu){
			this.menu = new Yacon.widget.TMenu(this.view.title.menu);
			this.menu.parent = this;
			this.menu.dataSet = this.dataSet;
			this.menu.page = this.page;
		}
		
		if(this.view.tableMenu){
			this.tableMenu = new Yacon.widget.TMenu(this.view.tableMenu);
			this.tableMenu.parent = this;
			this.tableMenu.dataSet = this.dataSet;
			this.tableMenu.page = this.page;
			html += this.tableMenu.getRightHtml(this.elementID+"-table-menu");
			
			this.rightMenu = this.tableMenu;
			
		}else{
			
			if(this.view.titleMenu){
				
				this.titleMenu = new Yacon.widget.TMenu(this.view.titleMenu);
				this.titleMenu.parent = this;
				this.titleMenu.dataSet = this.dataSet;
				this.titleMenu.page = this.page;
				html += this.titleMenu.getRightHtml(this.elementID+"-title-menu");
				
				this.rightMenu = this.titleMenu;
			}
			
			if(this.view.dataMenu){
				
				this.dataMenu = new Yacon.widget.TMenu(this.view.dataMenu);
				this.dataMenu.parent = this;
				this.dataMenu.dataSet = this.dataSet;
				this.dataMenu.page = this.page;
				html += this.dataMenu.getRightHtml(this.elementID+"-data-menu");
				
				this.rightMenu = this.dataMenu;
				
			}
			
		}
		
		html += "</div>";
		
		return html;
		
	},
	
	refresh: function(){
		this.dataSet.refresh();
	},
	
	/* 刷新组件 */
	refreshElement: function(){
		
		var html = "";
		
		this.view = this.dataSet.getDataValue();
		
		this.body.refresh();	
		
		this.addEvents();
		
	},
	
	/* 绑定动作 */
	addEvents: function(){
		
		Yacon.callBack(this.elementID+"_beforeEvent", [this,this.page]);
		
		/* 存在菜单 */
		if(!Yacon.isEmpty(this.menu)){		
			this.menu.addTopClick(".panel-heading");
			this.menu.addBottomClick(".panel-heading");	
		}
		
		this.body.addEvents();
		
		if(!Yacon.isEmpty(this.rightMenu)){
			
			this.rightMenu.addRightClick();
			
			if(this.isFirst){
				
				var self = this;
				
				Yacon.callBackRight(self.elementID+"-table-menu", self);
				Yacon.callBackRight(self.elementID+"-title-menu", self);
				Yacon.callBackRight(self.elementID+"-data-menu", self);
				
				self.isFirst = false;
				
			}

		}
		
		Yacon.callBack(this.elementID+"_afterEvent", [this,this.page]);
		
	},
	
	/* 布局前处理 */
	layoutBefore:function(){
		
		this.spinIn();
		this.spinHidden();
		
	},
	
	/**
	 * 获取所有选中表格
	 */
	getCheckCells: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		this.checkCells = new Array();
		
		var cellObjs = $(search + " .panel-body .table-responsive table.table tbody td.data-field.active");
		var length = cellObjs.length;
		
		for(var i=0;i<length;i++){
			var cellObj = cellObjs.eq(i);
			var activeObj = new Yacon.component.TMultiCell({
				activeCell : cellObj,
				page : this.page,
				parent: this.body,
				search: search
			});
			this.checkCells.add(activeObj);
		}
		
		return this.checkCells;

	},
	
	spinIn: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";

		this.spinner.createSpinner(search);
		
		this.spinner.spinIn(search);
		
	},
	
	spinOut: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";
		
		if(!Yacon.isEmpty(this.spinner)){
			this.spinner.spinOut(search);
		}	
		
	},
	
	spinShow: function(){
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";

		if(!Yacon.isEmpty(this.spinner)){
			this.spinner.spinShow(search);
		}
		
	},
	
	spinHidden: function(){
		
		var search = this.page.element.search + " div[lily-id='"+this.elementID+"'][lily-type='"+this.elementType+"']";

		if(!Yacon.isEmpty(this.spinner)){
			this.spinner.spinHidden(search);
		}
		
	}
		
};